# -*- coding: UTF-8 -*-
import requests
import json
import log_helper
import conf
import time

logger = log_helper.init_logging('http')


def response_json(data, url=conf.http_report_url):
    headers = {"Content-Type": "application/json"}
    post_data = json.dumps(data, ensure_ascii=False)
    logger.info("http_response:" + post_data)
    try_time = 0
    while try_time < 3:
        try:
            response = requests.post(url, data=post_data, headers=headers)
            if response.ok:
                logger.info("http_response_result:" + response.text)
                return
            logger.error("response status:" + str(response.status_code))
        except Exception as e:
            logger.error(e)
        time.sleep(0.1)
        try_time += 1
